<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<meta charset="utf-8">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <link rel="shortcut icon" href="favicon.ico">
    <link th:href="@{/css/bootstrap.min.css}" rel="stylesheet"/>
    <link th:href="@{/css/layui.css}" rel="stylesheet" >
    <link th:href="@{/css/font-awesome.css}" rel="stylesheet"/>
    <!-- bootstrap-table 表格插件样式 -->
    <link th:href="@{/ajax/libs/bootstrap-table/bootstrap-table.min.css}" rel="stylesheet"/>
    <link th:href="@{/ajax/libs/jqTreeGrid/jquery.treegrid.css}" rel="stylesheet"/>
    <link th:href="@{/css/animate.css}" rel="stylesheet"/>
    <link th:href="@{/css/style.css}" rel="stylesheet"/>
    <link th:href="@{/css/checkbox.css}" rel="stylesheet"/>
    <link th:href="@{/ajax/libs/select/select2.css}" rel="stylesheet"/>
    <link th:href="@{/ruoyi/css/ry-ui.min.css}" rel="stylesheet"/>
    <!-- Data Tables -->
    <link th:href="@{/css/plugins/dataTables/dataTables.bootstrap.css}" rel="stylesheet">
    <link href="/ajax/libs/jquery-layout/jquery.layout-latest.css" th:href="@{/ajax/libs/jquery-layout/jquery.layout-latest.css}" rel="stylesheet"/>
    <link href="/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css" th:href="@{/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css}" rel="stylesheet"/>
</head>
<link href="/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css" th:href="@{/ajax/libs/jquery-ztree/3.5/css/metro/zTreeStyle.css}" rel="stylesheet"/>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-role-edit" >
        <input id="roleId" name="roleId" type="hidden" />
        <div class="form-group">
            <label class="col-sm-3 control-label ">角色名称：</label>
            <div class="col-sm-8">
                <input class="form-control" th:value="${role.roleDescription}"  type="text" name="roleName" id="roleName" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">角色字符：</label>
            <div class="col-sm-8">
                <input class="form-control" th:value="${role.role}"  type="text" name="roleKey" id="roleKey" >
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">上级角色：</label>
            <div class="col-sm-8">
                <select id="parentRole" name="parentRole" class="form-control select2">
                    <option value="">无</option>
                    <option th:each="roleitem:${roleList}" th:value="${roleitem.roleId}" th:text="${roleitem.roleDescription}" th:selected="${roleitem.roleId eq role.parentId}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <div class="form-control-static col-sm-offset-9">
                <button type="button" onclick="edit()" class="btn btn-primary">提交</button>
                <button onclick="$.modal.close()" class="btn btn-danger" type="button">关闭</button>
            </div>
        </div>
    </form>
</div>
<script th:src="@{/js/jquery.min.js}"></script>
<script th:src="@{/js/bootstrap.min.js}"></script>
<!-- bootstrap-table 表格插件 -->
<script th:src="@{/ajax/libs/bootstrap-table/bootstrap-table.min.js}"></script>
<script th:src="@{/ajax/libs/bootstrap-table/locale/bootstrap-table-zh-CN.min.js}"></script>
<script th:src="@{/ajax/libs/bootstrap-table/extensions/mobile/bootstrap-table-mobile.min.js}"></script>
<script th:src="@{/ajax/libs/bootstrap-table/extensions/toolbar/bootstrap-table-toolbar.min.js}"></script>
<!-- jquery-export 表格导出插件 -->
<script th:src="@{/ajax/libs/bootstrap-table/extensions/export/bootstrap-table-export.js}"></script>
<script th:src="@{/ajax/libs/bootstrap-table/extensions/export/tableExport.js}"></script>
<!-- Data Tables -->
<script th:src="@{/js/plugins/dataTables/jquery.dataTables.js}"></script>
<script th:src="@{/js/plugins/dataTables/dataTables.bootstrap.js}"></script>
<script th:src="@{/js/plugins/jeditable/jquery.jeditable.js}"></script>
<script th:src="@{/ajax/libs/jquery-layout/jquery.layout-latest.js}"></script>
<script th:src="@{/ajax/libs/jquery-ztree/3.5/js/jquery.ztree.all-3.5.js}"></script>
<script th:src="@{/ajax/libs/layer/layer.min.js}"></script>
<script th:src="@{/ajax/libs/layui/layui.js}"></script>
<script th:src="@{/ruoyi/js/common.js?v=2.2.0}"></script>
<script th:src="@{/ruoyi/js/yuyu-ui.min.js?v=2.2.0}"></script>
<script th:inline="javascript">
    var role = [[${role}]];
    function edit() {
        var roleName = $("input[name='roleName']").val();
        var roleKey = $("input[name='roleKey']").val();
        var parentId =  $("#parentRole option:selected").val();
        var json={
            "roleId": role.roleId,
            "role":roleKey,
            "roleDescription":roleName,
            "parentId":parentId
        };
        $.ajax({
            type : "POST",
            url : "/role/edit",
            dataType: 'json',
            data : JSON.stringify(json),
            contentType:"application/json",
            error : function(request) {
                $.modal.alertError("系统错误");
            },
            success : function(data) {
               if (data.code==200){
                   parent.layer.msg('编辑成功', {icon: 1});
                   setTimeout(function () {
                       parent.refreshTable();
                       var index = parent.layer.getFrameIndex(window.name);
                       parent.layer.close(index);
                   },500);
               }
            }
        });
    }
</script>
</body>
</html>